#include "bookOrder.h"

using namespace std;

int OrderManager::getOrderNum () {
	return orders.empty() ? 0 : orders.size();
}

int OrderManager::addOrder(int iNum, const char* iName, const char* iAuthor) {
	BookOrder* mOrder = new BookOrder(iNum, iName, iAuthor);
	orders.push_back(*mOrder);
	return 0;
}

int OrderManager::delOrder(int iOrder) {
	int n = 0;
	BO::iterator i;
	for (i = orders.begin(); i != orders.end(); ++i) {
		if ((*i).getOrder() == iOrder) {
			orders.erase(i);
			++n;
		}
	}
	return n;
}

void OrderManager::priOrders() {
	BO::iterator i;
	for (i = orders.begin(); i != orders.end(); ++i) {
		printf("\33[32m [MARCO][%d]---[%d][%s][%s]---\33[0m\n", __LINE__, 
				(*i).getOrder(), (*i).getVal(B_NAME), (*i).getVal(B_AUTHOR)); 
	}
}

/* 把旧的删除掉.重新写进去. */
void OrderManager::saveToDB(const char* path) {
}

void OrderManager::readFromDB() {
}

